import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

// 添加被动触摸事件监听器来解决警告
document.addEventListener('touchmove', function() {}, { passive: true });
document.addEventListener('touchstart', function() {}, { passive: true });
document.addEventListener('touchend', function() {}, { passive: true });

import ElementUI from "element-ui";
import "@/assets/css/reset.css"; // 重置样式
import "@/styles/index.css"; // 自定义主题
import "@/store/axiosConfig.js"; //  axios 配置
// import '@/assets/css/font.css'


import WebSocketService from '@/utils/websocket'; // 引入我们封装的插件
Vue.prototype.$socket = new WebSocketService();


Vue.use(ElementUI, {
	// size: 'medium',
})
import { Message } from "element-ui";
// 混入
import _mixin from "@/mixins/index.js";
Vue.mixin(_mixin);
import { Loading } from "element-ui";
const load = {
	loading: null,
	open: function() {
		this.loading = Loading.service({
			fullscreen: true,
			lock: true,
			text: 'Loading',
		});
	},
	close: function() {
		if (!this.loading) return false;
		this.loading.close();
	},
};
Vue.prototype.$load = load;
// load.open();
// 提示
const duration = 1500; //提示时长
const showClose = false; //提示时长
const offset = 100; //提示时长
window.alert = function(res = {}) {
	if (typeof res == "object") {
		const {
			msg: message,
			code
		} = res;
		if (code == 1) {
			Message.success({
				message,
				showClose,
				offset,
				duration,
			});
		} else {
			Message.error({
				message,
				showClose,
				offset,
				duration,
			});
		}
	} else if (typeof res == "string") {
		Message.info(res);
	}
};
window.alertSucc = function(message) {
	Message.success({
		message,
		showClose,
		offset,
		duration: duration,
	});
};
window.alertErr = function(message, duration = 3000) {
	Message.error({
		message,
		showClose,
		duration,
	});
};
window.alertInfo = function(message) {
	Message.info({
		message,
		showClose,
		offset,
		duration: duration,
	});
};

// store.dispatch("appInit"); //重新初始化
Vue.prototype.$message = Message;
Vue.config.productionTip = false;
new Vue({
	router,
	store,
	render: (h) => h(App),
}).$mount("#app");